package com.itunic.cloud.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 实现Spring Security提供的UserDetails接口
 * 该类用于描述一个用户的实体信息，可以根据
 * 实际业务自行扩展。
 * @author Sean
 */
@Data
public class UserDetailsEntity implements UserDetails {
    private String id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 用户所拥有的权限集合
     */
    private Collection<? extends GrantedAuthority> authorities;

    public UserDetailsEntity(String id, String username, String password, Collection<? extends GrantedAuthority> authorities) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    /**
     * 判断用户是否处于非过期状态
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账户是否处于非锁定状态
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 密码是否过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 该用户是否为启用状态
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}